<%@ page import="com.google.appengine.api.datastore.DatastoreServiceFactory" %>
<%@ page import="com.google.appengine.api.datastore.DatastoreService" %>
<%@ page import="com.google.appengine.api.datastore.Key" %>
<%@ page import="com.google.appengine.api.datastore.KeyFactory" %>
<%@ page import="com.google.appengine.api.datastore.Entity" %>
<%@ page import="com.google.appengine.api.datastore.EntityNotFoundException" %>
<%@ page import="com.google.appengine.api.images.*" %>
<%@ page import="com.google.appengine.api.blobstore.BlobKey" %>

<%
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

Key entityKey = KeyFactory.stringToKey(request.getParameter("entityKey"));
 Entity file = null;
try {
	file = datastore.get(entityKey);
} catch (EntityNotFoundException e) {
	e.printStackTrace();
}
String type = file.getProperty("contentType").toString().split("/")[0];
String imageURL = null;
if (type.equals("image")) {
	BlobKey blobKey = (BlobKey) file.getProperty("blobKey");
	ImagesService image = ImagesServiceFactory.getImagesService();
	imageURL = image.getServingUrl(blobKey, 300, true);
}
%>

<html>

	<body>
		<% if (type.equals("image")) { %>
			<img class="thumbnail" src="<%= imageURL %>" title="<%= file.getProperty("fileName") %>" />
		<% } else if (type.equals("video")) { %>
			<img class="thumbnail" src="images/video.png" title="<%= file.getProperty("fileName") %>" />
		<% } else if (type.equals("audio")) { %>
			<img class="thumbnail" src="images/audio.png" title="<%= file.getProperty("fileName") %>" />
		<% } else { %>
			<img class="thumbnail" src="images/doc.png" title="<%= file.getProperty("fileName") %>" />
		<% }%>
		<div style="overflow: hidden;"><div style="margin-top: 10px;" class="desc">Name: <%= file.getProperty("fileName") %></div><div class="desc">Media Type: <%= file.getProperty("contentType") %></div></div>
		<div class="status">Status: Uploaded</div>
	</body>
</html>